<template>
  <el-dialog v-model="visible" modal-class="audit-dialog" width="500" align-center center :show-close="false">
    <div class="sure">
      <div>
        <el-icon v-if="type === 'error' || type === 'error-msg'">
          <Warning />
        </el-icon>
        <p v-show="title" class="title">{{ title }}</p>
      </div>
      <slot name="message">
        <span class="f12">{{ message }}</span>
      </slot>
      <div class="error-list" v-if="errorList.length > 0">
        <p class="f12 pd8 mt10 error-item" v-for="(item, index) in errorList" :key="index">
          <template v-if="item.quoteType === 1">
            <span class="gray f12">共{{ item.totalType }}款，任选数量：{{ item.canCheckNum }}/</span>
            <span class="gray f12">已选：{{ item.checkedNum }}</span>
          </template>
          <template v-else>
            <span class="gray f12">{{ item.quotaName }}：</span>可选数量：{{ item.canCheckNum }}/<span class="gray f12"
              >已选：{{ item.checkedNum }}</span
            >丨可选金额：¥{{ item.canCheckMoney }}/
            <span class="gray f12">已选：¥{{ item.checkedMoney }}</span>
          </template>
        </p>
      </div>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <div class="mt20" v-if="type === 'error-msg'">
          <el-button type="primary" @click="cancel" style="width: 120px">我知道了</el-button>
        </div>
        <div class="mt20" v-else>
          <el-button type="info" @click="cancel" style="width: 120px">取消</el-button>
          <el-button type="primary" @click="submit" style="width: 120px">{{ submitBtnText }}</el-button>
        </div>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { computed, ref } from "vue";

const props = defineProps({
  type: {
    type: String,
    default: "error" //error error-msg
  },
  title: {
    type: String,
    default: ""
  },
  submitBtnText: {
    type: String,
    default: "确认返还"
  },
  isOpen: {
    type: Boolean,
    default: false
  },
  message: {
    type: String,
    default: "---"
  },
  errorList: {
    type: Array,
    default: () => []
  }
});
const emit = defineEmits(["update:isOpen", "submit", "cancel"]);
const visible = computed({
  get() {
    return props.isOpen;
  },
  set(value) {
    emit("update:isOpen", value);
  }
});

const submit = () => {
  emit("submit");
};

const cancel = () => {
  visible.value = false;
  emit("cancel");
};
</script>

<style scoped lang="scss">
.error-item {
  background: #eef1f4;
  text-align: left;
  .gray {
    color: #424e66;
  }
}
.el-button--primary {
  --el-button-bg-color: #424e66;
  border: none;
}
.el-button.el-button--info {
  --el-color-info: #f2f3f5;
  --el-color-white: #1d2129;
  &:hover {
    --el-button-hover-bg-color: #f2f3f5 !important;
    border-color: #f2f3f5 !important;
  }
}
.title {
  color: #3d3d3d;
  font-size: 20px;
  margin-bottom: 32px;
}
.sure {
  text-align: center;
  span {
    font-size: 14px;
    color: #3d3d3d;
    line-height: 20px;
  }

  ::v-deep(.el-icon) {
    font-size: 60px;
    margin-bottom: 20px;
    color: rgb(255, 51, 51);
  }
}
.audit-dialog {
  .goods-detail {
    margin-bottom: 20px;
  }
}

.alert {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 54px;
  margin: 0 0 10px;
  background: #ffd9c2;
  border-radius: 6px;

  .el-icon {
    color: #e37318;
    margin: 0 10px;
  }
}

.dialog-footer-flex {
  display: flex;
  justify-content: space-between;
}
</style>
